package com.anji.plus.gaea.inf;

import com.anji.plus.gaea.inf.intercepter.AppSecretInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ultrajiaming
 * @since 2021/3/17 13:27
 */
@Configuration
@AutoConfigurationPackage
@ComponentScan(basePackages = {"com.anji.plus.gaea.inf.module.dynamic"})
@MapperScan(basePackages = {"com.anji.plus.gaea.inf.module.dynamic"})
public class InfConfig {

    @Bean
    public AppSecretInterceptor appSecretInterceptor() {
        return new AppSecretInterceptor();
    }

    @Configuration
    @ConditionalOnClass(WebMvcConfigurer.class)
    class InfWebMvcConfig implements WebMvcConfigurer {

        @Autowired
        private AppSecretInterceptor appSecretInterceptor;

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(appSecretInterceptor)
                    .addPathPatterns("/custom/dynamic/execute");
        }
    }

}
